Skip to content

compiler: fall back to local on distributed-compile failure - #2777

Open
jetm wants to merge 9 commits into
mozilla:mainfrom
jetm:compiler-local-fallback
Open

jetm wants to merge 9 commits into
mozilla:mainfrom
jetm:compiler-local-fallback

Conversation

@jetm

@jetm jetm commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2775 (splitting the OpenEmbedded/Yocto sccache-dist work into focused
PRs; replaces the closed #2750).

Rebased onto current main (dac6c80). This revision adds a [dist] fallback
switch, following the feature-flag suggestion in the comments.

Problem

Any remote failure during a distributed compile - a non-zero result or a dropped
output - failed the whole build instead of just the distribution, so a single
input that misbehaved remotely broke the build. The usual case is an assembler
source that .incbins a generated file: the file is not among the shipped inputs,
the remote assembler fails, and the build stops. Separately, sccache's own log
output on stderr corrupted autoconf/libtool probe output (for example a libtool
-fPIC probe reading wrapper logs off stderr).

Approach

  • Treat a distributed-compile failure (a non-zero remote result, or a declared
    output that did not materialize) as a trigger to recompile locally.
  • Honor optional outputs so a missing optional artifact does not fail the
    compile.
  • Route wrapper log output off the compiler's stderr.
  • Log the distribute/local decision at info and any remote failure at debug, so
    the fallback path is diagnosable.
  • Add a boolean fallback key to the [dist] section of the client
    configuration. It defaults to true, which recompiles locally as above.
    fallback = false returns the remote result with its exit code and stderr, as
    0.19.0 does.

Compatibility

The key is new. Unknown keys are denied when the configuration is parsed, so an
older binary rejects a configuration that contains fallback;
leaving the key out keeps every existing configuration working. With the key absent
the behavior changes from 0.19.0: a failed remote compile is recompiled locally
instead of reported.

Test

The existing failed-compile unit test and its Docker-based dist twin keep every
assertion and run with fallback = false. Two new tests cover both modes. On the
rebased branch the format check, the build, the unit tests and the Docker-based
dist tests all pass.

Evidence

A distributed build of a Linux kernel package on three build hosts with only
the wave-1 changes (this branch and #2776) and the default fallback = true took 562 s; the same
build without distribution takes 881 s. Of 25,548 compile requests, 25,156 were
distributed and 392 ran locally. 4 of those were assembler sources that embed a
generated file, which fail remotely and recompile locally, as intended. The other
388 were scheduler capacity rejections, which already fell back to local
compilation before this change.

On a local client, a source that embeds a missing file exits 0 by default and
exits 1 with fallback = false; a source with a real compile error exits 1 in both
modes.

@AJIOB

AJIOB commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Hi, thanks for the PR.

Looks like it also resolves #2700 and #2745

@AJIOB

AJIOB commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

For discussion: maybe we need a feature flag for that

@AJIOB

AJIOB commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Hi @sylvestre ,

Is it OK for you?

@codecov-commenter

codecov-commenter commented Jul 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.94118% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.80%. Comparing base (01bf270) to head (b46e138).

Files with missing lines Patch % Lines
src/compiler/compiler.rs 97.22% 10 Missing ⚠️
src/server.rs 66.66% 2 Missing ⚠️
tests/oauth.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2777      +/-   ##
==========================================
+ Coverage   80.68%   80.80%   +0.11%     
==========================================
  Files          78       78              
  Lines       48610    48999     +389     
==========================================
+ Hits        39223    39595     +372     
- Misses       9387     9404      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 62 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing jetm:compiler-local-fallback (b46e138) with main (01bf270)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@jetm
jetm force-pushed the compiler-local-fallback branch from 974dbe8 to 9ba6fa7 Compare August 21, 2026 16:20
@jetm

jetm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@AJIOB thanks for looking at this.

Yes, it covers #2745 directly and should also resolve #2700. #2745 asks for the retry-locally behaviour plus visibility, and both are here: the fallback is logged at info (which server, and why it fell back) with the remote's stderr at debug, and the failure is already counted as dist_errors in sccache --show-stats, so a degraded cluster shows up rather than silently slowing the build. For #2700 the .incbin compile fails on the remote and previously took the build down with it; with this change it is retried locally and the build completes.

On the feature flag: I defaulted it to on because the alternative is a hard build failure for something sccache can recover from, which is what #2745 is asking to avoid. The counter-argument I see is CI, where you might prefer a loud failure over silently slower local builds masking a broken cluster. I am happy to add an opt-out for that, either a dist.fallback config key defaulting to true or an env override. Want me to add it in this PR, and do you have a preference on the name?

On the red dist-tests: that failure was pre-existing on the base I branched from, not from this change. main at 7cd4f2c fails the same two tests with no patches applied (test_dist_cargo_build and test_dist_cargo_makeflags, both expecting dist_compiles == 1 and getting 0): https://github.com/mozilla/sccache/actions/runs/29833785987. I have rebased onto current main, which picks up the dist test fixes and the MSRV bump. The new workflow runs are sitting in action_required, so they need an approval to start.

@jetm

jetm commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@AJIOB the flag is in: a fallback key in the [dist] section of the client configuration, default true. With fallback = false the remote result reaches the client with its exit code and stderr, as in 0.19.0, and upstream's failed-compile test runs in that mode with every assertion intact. An older binary rejects a configuration that contains the key. I rebased onto current main and updated the description. It also resolves #2700 and #2745, as you noted.

@jetm

jetm commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve the pending workflow runs on #2776 and #2777? Both branches are rebased onto current main and pass the full test suite locally, including the Docker-based dist tests.

@jetm
jetm force-pushed the compiler-local-fallback branch 2 times, most recently from 909138a to 8d47f8e Compare November 5, 2026 15:17
jetm added 8 commits November 27, 2026 18:20
sccache logged the distribute-vs-local decision only at debug ("Compiling
locally", "Attempting distributed compilation"), while an infrastructure
fallback warned. At info a successful distribution and a local compile were
both silent, so the only visible dist signal was the failure path - leaving
no way to see the distribute/fallback ratio without the full debug firehose.
Diagnosing why a distributed build under-distributes meant guessing.

Promote the decision points to info and add a log on successful
distribution naming the server and exit code, so SCCACHE_LOG=info gives a
per-compile dist trace (attempt then distributed-on-server, compiled-locally,
or falling-back-with-reason). sccache only emits logs when SCCACHE_LOG is
set, so default runs are unaffected.

Signed-off-by: Javier Tia <javier@peridio.com>
A distributed compile the build-server rejects is often a distribution
artifact, not a genuine compiler error: an object that .incbin's a binary the
inputs packager does not ship - the kernel's vdso, embedded-config, and dtb
wrappers - cannot be assembled remotely and returns non-zero, which failed the
whole build with no recourse and forced the kernel to be excluded wholesale.

Treat a non-zero remote result as a fallback trigger rather than a terminal
error: recompile locally, which either succeeds (confirming a dist-only
artifact) or reproduces the genuine error. A remote failure can no longer
break a build that would compile locally. Only failing dist compiles are
affected - successful ones are returned unchanged - so the kernel now
distributes (1124/1128 compiles), with its handful of .incbin objects falling
back to local.

Signed-off-by: Javier Tia <javier@peridio.com>
A distributed compile can return a successful (exit 0) result yet omit a
declared output. glibc's ldconfig.o and sprof.o compile fine on the
build-server, but it does not return their `.o.dt` dependency file, so zipping
the compiler outputs fails fatally ("failed to open file ...o.dt: No such file")
with no recourse. One dropped output among 6427 forced glibc to be excluded from
distribution wholesale, even though 6425 of its compiles distribute cleanly.

Capture the declared output paths before the compilation is moved into the
packagers, and after a successful remote compile verify each one exists on disk.
A missing output is a distribution artifact, not a compiler error, so bail into
the existing local-recompile fallback (the same one that already salvages
non-zero remote results), which reproduces the full output set. Only compiles
whose dist output set is incomplete are affected; complete ones are returned
unchanged. glibc now distributes, with ldconfig.o and sprof.o falling back to
local.

Signed-off-by: Javier Tia <javier@peridio.com>
When sccache runs as a compiler wrapper (`sccache <compiler> ...`) it
shares stderr with the wrapped compiler. A build's feature probes treat
any unexpected stderr as a compiler failure: libtool's -fPIC check
(_LT_COMPILER_OPTION) sets pic_flag="" whenever the probe compile emits
stderr, even on exit 0. With SCCACHE_LOG set, the client's own
env_logger records ("Attempting to read config file", "Server sent
CompileStarted") landed on that shared stderr, so an autotools package
configured with pic_flag="" and produced non-PIC objects that failed to
link into a shared library (relocation R_X86_64_32 ... recompile with
-fPIC). It looked concurrency-dependent because the client's startup
logging varies with server-connection timing, so the probe stderr only
sometimes diverged from libtool's expected boilerplate.

Initialize logging after parsing the command so the compile-wrapper case
can choose its target: route sccache's own records to SCCACHE_ERROR_LOG
when set, keep stderr only when it is an interactive terminal (so
`SCCACHE_LOG=debug sccache gcc ...` at a prompt still shows logs), and
discard them when stderr is captured by a build. The wrapped compiler's
forwarded stderr is untouched.

Signed-off-by: Javier Tia <javier@peridio.com>
When a distributed compile exits non-zero the client logs only the exit
code and falls back to a local recompile, discarding the remote compiler's
stdout and stderr. That output is the only place the actual failure is
visible - a missing target std, an input the packager did not ship, a
sandbox path that does not resolve - so diagnosing a dist regression meant
patching in a temporary dump and rebuilding the binary each time.

Emit the remote stdout/stderr at debug on the non-zero path. SCCACHE_LOG=debug
now surfaces the real remote error with no rebuild, while a normal
SCCACHE_LOG=info run stays quiet (the one-line fallback reason is still logged
at warn by the caller).

Signed-off-by: Javier Tia <floss@jetm.me>
Signed-off-by: Javier Tia <javier@peridio.com>
Kernel assembler sources that .incbin generated files fail on the
build server, because the generated file is not among the shipped
inputs. Upstream 0.19.0 reports that remote exit code to the client
as the result of the compile. The fork needs the opposite: the client
recompiles such a unit locally, so the kernel build still completes.
The two behaviours cannot share one code path without one of the
upstream remote-exit-code tests losing its assertions.

Add a boolean key `fallback` to the [dist] section of the client
configuration. It defaults to true, which keeps the fork behaviour,
and false selects the upstream 0.19.0 behaviour. This commit adds only
the key, its documentation and a unit test parsing both the explicit
value and the default; the compiler honors the key in the next
commit. Because unknown keys are denied, an older binary rejects a
configuration that contains the key, which the documentation states.

Signed-off-by: Javier Tia <floss@jetm.me>
Signed-off-by: Javier Tia <javier@peridio.com>
A non-zero remote exit code or a missing declared output unconditionally
triggered a local recompile. That contradicts upstream's behaviour, where
the remote result reaches the client with its exit code and stderr, and
it contradicts upstream's test for that case.

Both bails in the dist compile path now consult the `[dist] fallback`
key through a provided DistClient method, defaulting to true so the
kernel build keeps recompiling locally. With false the remote result is
returned as release 0.19.0 does. The HTTP client carries the value from
the dist configuration; test clients override it. Upstream's failed
compile test and its docker-based integration twin keep every assertion
and run with fallback false, and two new tests cover both modes.

Signed-off-by: Javier Tia <floss@jetm.me>
…mpile

After a successful remote compile the client fell back to a local
recompile only when a declared output path did not exist. A stale
object from an earlier build sits at that path, so a server that
dropped the output still passed the check and the stale file was
cached as the result of the new compile.

Match each declared output against the set the server returned. gcc's
dependency file is the exception: the local preprocessor writes it and
the server never returns it, so it keeps the existence check. Without
that exemption every -MD compile would fall back locally.

Signed-off-by: Javier Tia <javier@peridio.com>
@sylvestre
sylvestre force-pushed the compiler-local-fallback branch from 8d47f8e to 1178a21 Compare November 27, 2026 17:20
Comment thread src/lib.rs
// Logging is initialized after parsing so the compile-wrapper case can keep
// sccache's own log records off the wrapped compiler's stderr.
init_logging(&command);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated to the fallback, please split it into its own PR

Comment thread src/lib.rs
@@ -126,6 +128,35 @@ fn init_logging() {
builder.format_timestamp_millis();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so SCCACHE_LOG=debug in CI or under make now prints nothing at all?
the user explicitly asked for these logs, discarding them silently seems wrong

Comment thread src/lib.rs
@@ -126,6 +128,35 @@ fn init_logging() {
builder.format_timestamp_millis();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the log file can't be opened, we silently drop everything?
commands.rs bails in that case

Comment thread src/compiler/compiler.rs
debug!("[{}]: Compiling locally", out_pretty);
info!(
"[{}]: Compiling locally (not eligible for distributed compilation)",
out_pretty

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is logged at info on every compile, including for people without dist configured
and "not eligible" is wrong when there is simply no dist client
please keep it at debug

Comment thread src/compiler/compiler.rs
.collect::<Option<_>>()
.context("Failed to adapt an output path for distributed compile")?;
// The local paths every declared output must occupy once the compile
// finishes. Captured before `compilation` is moved into the packagers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody will read such a long comment :)
please make it shorter (same for the ones at the bail! below)

Comment thread src/compiler/compiler.rs
path_transformer
.as_dist_abs(&local)
.map(|dist| (dist, local, output.key == "d"))
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matching on the key "d" feels fragile, does it hold for nvcc/nvhpc too?
could the output carry this information instead?

Comment thread src/compiler/compiler.rs
@@ -4261,6 +4654,137 @@ mod test_dist {
fn rewrite_includes_only(&self) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is almost a copy of OneshotClient, could be dedup, no?
new and dropping are also the same code twice

Comment thread docs/Configuration.md
@@ -46,6 +46,12 @@ scheduler_url = "http://1.2.3.4:10600"
toolchains = []
# the maximum size of the toolchain cache in bytes
toolchain_cache_size = 5368709120

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make the comment shorter, no need to document what older binaries do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants